package cn.sdormitory.controller.report;

import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.report.service.AttenceStatisticsService;
import cn.sdormitory.report.vo.AttenceStatisticsVO;
import com.alibaba.excel.EasyExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @创建人：zhouyang
 * @创建时间：2020/12/3 19:18
 * @version：V1.0
 */
@RestController
@Api(tags = "Report-AttenceStatistics=> 考勤统计")
@RequestMapping("/report/attencestatistics")
public class AttenceStatisticsController {
    @Autowired
    private AttenceStatisticsService attenceStatisticsService;

    @ApiOperation("list => 查询正常出勤率统计列表")
    @PreAuthorize("@ss.hasPermi('report:attencestatistics:list')")
    @GetMapping(value = "/list")
    public CommonResult<CommonPage<AttenceStatisticsVO>> list(@RequestParam Map<String, Object> params) {


        CommonPage<AttenceStatisticsVO> taskTotalVoList
                = attenceStatisticsService.getAttenceStaList(params,Integer.parseInt((String)params.get("pageNum")),
                Integer.parseInt((String)params.get("pageSize")));
        return CommonResult.success(taskTotalVoList);

    }


    @ApiOperation("hygienelist =>导出宿舍考勤统计信息")
    @PreAuthorize("@ss.hasPermi('report:attencestatistics:attencelist')")
    @GetMapping(value = "/exportattencelist")
    public CommonResult export(HttpServletResponse response, @RequestParam Map<String, Object> params) {

        List<AttenceStatisticsVO> attenceStatisticsVOList = attenceStatisticsService.getAttenceStaListExport(params);
        try {
            EasyExcel.write(response.getOutputStream(), AttenceStatisticsVO.class).sheet("宿舍考勤统计管理").doWrite(attenceStatisticsVOList);
            return CommonResult.success();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return CommonResult.failed();

    }


}
